/*
 * 开发环境webpack配置
 * @author li.xiaomei
 * @date 2016-12-19
 */
var webpack = require('webpack')
var merge = require('webpack-merge')

var baseConfig = require('./base.config.js')
var commonMethod = require('../method.js')
var webpack_config = global.think_config.webpack

module.exports = function (){
  var base_config = baseConfig('dev');

  var webConfig = {
    debug: true,

    noInfo: true,

    module: {
      loaders: commonMethod.styleLoaders({
        sourceMap: webpack_config.dev.cssSourceMap,
        extract: webpack_config.dev.extract
      })
    },

    ouput: webpack_config.dev.output,
    devtool: webpack_config.devtool,

    plugins: [
      new webpack.DefinePlugin({
        'process.env.NODE_ENV': JSON.stringify('development'), // Tells React to build in either dev or prod modes. https://facebook.github.io/react/downloads.html (See bottom)
        __DEV__: true
      }),
      new webpack.optimize.UglifyJsPlugin({
        compress: {
          warnings: false,
          booleans: false,
          unused: false
        }
      }),
      // https://github.com/glenjamin/webpack-hot-middleware#installation--usage
      new webpack.optimize.OccurenceOrderPlugin(),
      new webpack.HotModuleReplacementPlugin(),
      new webpack.NoErrorsPlugin(),
    ]
  }

  //热更新配置
  if(commonMethod.findArgv('hot') && base_config.entry) {
    for(var fname in base_config.entry) {
      if(base_config.entry.hasOwnProperty(fname)) {
        base_config.entry[fname] = ['webpack-hot-middleware/client?reload=true'].concat(base_config.entry[fname]);
      }
    }
  }
  
  return merge(base_config, webConfig)
}
